package controllers

import (
	"map/models"
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego"
	"map/libs"
)

type CompanyController struct {
	BaseController
}

func (this *CompanyController) Create(){
	c:=models.Company{}
	if err := this.ParseForm (&c) ;err!=nil{
		this.errors("请检查输入格式",1)
	}
	b,msg:=c.Valid()
	if !b {
		this.errors(msg,1)
	}
	
	f, h, err := this.GetFile("image")
	if err ==nil{
		defer f.Close()
		url,name:=libs.FilePath(h)
		this.SaveToFile("image",url)
		c.Image=name
	}
	
	_,err=orm.NewOrm().Insert(&c)
	if err !=nil{
		beego.Error("公司添加失败",err)
		this.errors("公司添加失败",1)
	}
	this.success("")
}